package com.xzit.day04.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzit.day04.entity.Emp;
import com.xzit.day04.mapper.EmpMapper;
import com.xzit.day04.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    public void add(Emp emp) {
        empMapper.insert(emp);
    }

    public void deleteById(int id) {
        empMapper.deleteById(id);
    }

    public void deleteByCondition(Emp emp) {
        empMapper.findByCondition(emp);
    }

    public void update(Emp emp) {
        empMapper.update(emp);
    }

    public Emp findById(int id) {
        return empMapper.findById(id);
    }

    public List<Emp> findAll() {
        return empMapper.findAll();
    }

    public PageInfo<Emp> findAllByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(empMapper.findAll());
    }

    public PageInfo<Emp> findByConditionByPage(Emp emp, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(empMapper.findByCondition(emp));
    }
}
